﻿// Problem 2
// 
// Find the sum of all the even-valued terms in the Fibonacci sequence 
// which do not exceed four million.
//
// correct ans 4613732 
#light
    
let fibonacci =
    let rec inner a b =
        seq {   let c = a + b 
                yield c
                yield! inner b c }
    seq {   yield 1
            yield 1
            yield! inner 1 1 }  
          
let answerProblem max =
    fibonacci
    |> Seq.takeWhile (fun (elem) -> elem < max)
    |> Seq.filter (fun (elem) -> elem % 2 = 0) 
    |> Seq.sum

let solve() = answerProblem 4000000